<template>
  <div class="track-list">
    <div class="context-menu" />

    <div class="menu">
      <div
        v-for="item in fromData"
        :key="item.id"
        class="track"
        @dblclick="playMusic(item.id)"
      >
        <img :src="item.al.picUrl" alt="" class="imgs">
        <div class="title-and-artist">
          <!-- <div class="container"> -->
          <div class="title">{{ item.name }}</div>
          <div class="artist">{{ item.ar[0].name }}</div>
          <!-- </div> -->
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import bus from '../../../assets/eventBu'

import { getPlaylist, getSonglistDetails } from '@/api/MS/index.js'
export default {
  data() {
    return {
      createTime: null,
      fromData: []
    }
  },
  created() {
    this.getPlaylist()
    // this.getSonglistDetails()
  },
  mounted() {},
  computed: {
    ...mapState(['userInfo'])
  },
  methods: {
    // 获取用户歌单
    async getPlaylist() {
      const id = this.userInfo.id
      const { data } = await getPlaylist({
        uid: id
      })
      // console.log(data)
      this.createTime = data.playlist[0].id
      // console.log(this.createTime)
      this.getSonglistDetails()
    },
    // 获取歌单详情
    async getSonglistDetails() {
      // console.log(this.createTime)
      const { data: res } = await getSonglistDetails({
        id: this.createTime,
        cookie: this.$store.state.cookie
      })
      // console.log(res)
      // data.playlist.tracks.slice(0, 11)
      this.fromData = res.playlist.tracks.slice(0, 12)
      // console.log(res.playlist.tracks.slice(0, 12))
      // console.log(this.fromData)
      console.log(res.privileges)
    },
    // 播放歌曲获取id
    playMusic(id) {
      // console.log(id)
      bus.$emit('add', id)
    }
  }
}
</script>

<style scoped lang="less">
.context-menu {
  background-color: salmon;
  width: 100%;
  height: 100%;
}
.menu {
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  .track:hover {
    background-color: #f5f5f7;
  }
  .track {
    width: 30%;
    display: flex;
    align-items: center;
    padding: 8px;
    border-radius: 12px;
    .imgs {
      height: 36px;
      width: 36px;
      border-radius: 6px;
      margin-right: 14px;
      cursor: pointer;
    }
    .title-and-artist {
      flex: 1;
      display: flex;
      flex-direction: column;
      .title {
        font-size: 16px;
        font-weight: 600;
        color: #000;
      }
      .artist {
        font-size: 12px;
      }
      .artist:hover {
        text-decoration: underline;
        cursor: pointer;
      }
    }
  }
}
</style>
